package com.sh.healthtv.view;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.sh.healthtv.R;


public class CommonDialog extends Dialog {

    private Button leftBtn;

    private Button rightBtn;

    private TextView msg;

    private Window window = null;

    public CommonDialog(Context context) {
        super(context, R.style.dialog_fullscreen);
        setDisplay();
    }

    public void setDisplay() {
        setContentView(R.layout.dialog_bg);// 设置对话框的布局
        msg = (TextView) this.findViewById(R.id.dialog_msg_tv);
        leftBtn = (Button) this.findViewById(R.id.dialog_left_bt);
        rightBtn = (Button) this.findViewById(R.id.dialog_right_bt);
        setProperty();
    }

    public Button getLeftBtn() {
        return leftBtn;
    }

    public void setLeftBtn(Button leftBtn) {
        this.leftBtn = leftBtn;
    }

    public Button getRightBtn() {
        return rightBtn;
    }

    public void setRightBtn(Button rightBtn) {
        this.rightBtn = rightBtn;
    }

    /**
     * 区分提示框类型(单按钮默认只用左按钮)，1、为两个按钮的提示框(确定、取消)。2、为单独按钮提示框。(确定)
     *
     * @param type
     * @return void
     * @throws
     * @Title: setContent
     * @author YuanGang
     * @date 2015年3月12日 上午10:50:06
     */
    public void setContent(String msgs, int type) {
        msg.setText(msgs);
        switch (type) {
            case 1:
                leftBtn.setVisibility(View.VISIBLE);
                rightBtn.setVisibility(View.VISIBLE);
                leftBtn.setBackgroundResource(R.drawable.dialog_btn_left);
                break;
            case 2:
                leftBtn.setVisibility(View.VISIBLE);
                rightBtn.setVisibility(View.GONE);
                leftBtn.setBackgroundResource(R.mipmap.dialog_long_btn);
                break;
            default:
                break;
        }
    }

    // 要显示这个对话框，只要创建该类对象．然后调用该函数即可．
    public void setProperty() {
        window = getWindow();// 　　　得到对话框的窗口．
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;// 这两句设置了对话框的位置．0为中间
        wl.y = 0;
        wl.alpha = 1;// 这句设置了对话框的透明度
        wl.gravity = Gravity.CENTER;

        window.setAttributes(wl);
    }

}
